//package com.daxt.service.impl;
//
//import java.io.InputStream;
//import java.io.UnsupportedEncodingException;
//import java.time.LocalDateTime;
//import java.time.format.DateTimeFormatter;
//import java.util.UUID;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//import org.springframework.util.Base64Utils;
//import org.springframework.util.StringUtils;
//import org.springframework.web.multipart.MultipartFile;
//
//import com.daxt.common.result.Result;
//import com.daxt.common.result.ResultCode;
//import com.daxt.common.result.ResultUtil;
//import com.daxt.mapper.sys.InfoMapper;
//import com.daxt.model.constant.SystemConfig;
//import com.daxt.model.service.file.Info;
//import com.daxt.service.OSSService;
//import com.daxt.utils.FileCopyUtil;
//
//
//@Service
//public class OssServiceImpl implements OSSService{
//
////	@Value(value = "${systemConfig.tempPath}")
////	private String basePath;
////	@Value(value = "${systemConfig.ossDir}")
////	private String ossDir;
//
//	@Autowired
//	private InfoMapper infoMapper;
//
////	/**
////	 * @description: 动态存储模式
////	 *
////	 * @author: lig
////	 * @date: 2021/7/22
////	 */
////	@Override
////	public Result<String> upload(String bucketName, String type, MultipartFile file) {
////		try {
////			InputStream inputStream = file.getInputStream();
////			int lastIndexOf = file.getOriginalFilename().lastIndexOf(".");
////			String substring = file.getOriginalFilename().substring(lastIndexOf);
////			PutObjectOptions options = new PutObjectOptions(inputStream.available(), -1);
////			options.setContentType(file.getContentType());
////			//存储模式
////            String accType = RedisUtil.getSysConfig(SystemConfigType.ACCESSORY_TYPE);
////            if(StringUtils.isEmpty(accType))return ResultUtil.data(ResultCode.RESULT_ERROR.getCode(), "系统配置缺少‘ACCESSORY_TYPE’存储类型", null);
////            String objectName = type+"/"+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMM")) + "/" + UUID.randomUUID() + substring;
////			String filePath = "";
////            if(accType.equals(AccessoryType.TYPE_1.getKey())){
////                filePath = FileBaseUtil.uploadFile(bucketName, objectName , inputStream,SystemConfig.ossDir);
////
////            }else if(accType.equals(AccessoryType.TYPE_2.getKey())){
////				filePath = MinioUtil.uploadFile(bucketName, objectName, inputStream,
////						options);
////            }else{
////				filePath = MinioUtil.uploadFile(bucketName, objectName, inputStream,options);
////			}
////			if (!StringUtils.isEmpty(filePath)) {
////				Info entity=new Info();
////				entity.setBucketName(bucketName);
////				entity.setFilePath(filePath);
////				entity.setFileName(file.getOriginalFilename());
////				entity.setCreateTime(LocalDateTime.now());
////				entity.setFileType(type);
////				infoMapper.insert(entity);
//////				return ResultUtil.data(ResultCode.RESULT_SUCCESS.getCode(), null, SystemConfig.ossIp+ filePath);
////				return ResultUtil.data(ResultCode.RESULT_SUCCESS.getCode(), null, SystemConfig.showOssFile + filePath);
////			}
////		} catch (Exception e) {
////			e.printStackTrace();
////			return ResultUtil.data(ResultCode.RESULT_ERROR.getCode(), null, null);
////		}
////		return ResultUtil.data(ResultCode.RESULT_ERROR.getCode(), null, null);
////	}
//	@Override
//	public Result<String> upload(String bucketName, String type, MultipartFile file) {
//		try {
//			InputStream inputStream = file.getInputStream();
//			int lastIndexOf = file.getOriginalFilename().lastIndexOf(".");
//			String substring = file.getOriginalFilename().substring(lastIndexOf);
//			/*PutObjectOptions options = new PutObjectOptions(inputStream.available(), -1);
//			options.setContentType(file.getContentType());
//			String filePath = MinioUtil.uploadFile(bucketName, type+"/"+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMM")) + "/" + UUID.randomUUID() + substring, inputStream,
//					options,file.getSize());*/
//
//			String filePath=FileCopyUtil.uploadFile(bucketName, type+"/"+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMM")) + "/" + UUID.randomUUID() + substring, inputStream,SystemConfig.ossDir);
//			if (!StringUtils.isEmpty(filePath)) {
//				Info entity=new Info();
//				entity.setBucketName(bucketName);
//				entity.setFilePath(filePath);
//				entity.setFileName(file.getOriginalFilename());
//				entity.setCreateTime(LocalDateTime.now());
//				entity.setFileType(type);
//				infoMapper.insert(entity);
//				return ResultUtil.data(ResultCode.RESULT_SUCCESS.getCode(), null, SystemConfig.showOssFile+ filePath);
//			}
//			} catch (Exception e) {
//			e.printStackTrace();
//			return ResultUtil.data(ResultCode.RESULT_ERROR.getCode(), null, null);
//		}
//		return ResultUtil.data(ResultCode.RESULT_ERROR.getCode(), null, null);
//	}
//
////	@Override
////	public Result<String> uploadSaveName(String bucketName, String type, MultipartFile file) {
////		try {
////			InputStream inputStream = file.getInputStream();
////
////			int lastIndexOf = file.getOriginalFilename().lastIndexOf(".");
////			String substring = file.getOriginalFilename().substring(lastIndexOf);
//////			String fileName = file.getOriginalFilename().substring(0,lastIndexOf);
////			/*PutObjectOptions options = new PutObjectOptions(inputStream.available(), -1);
////			options.setContentType(file.getContentType());
////			System.out.println(file.getSize());
////			String filePath = MinioUtil.uploadFile(bucketName,type+"/"+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMM")) + "/" + UUID.randomUUID() + substring, inputStream,
////					options,file.getSize());*/
//////			//edit by lig 2021-07-22 修改上传原始文件名
//////			String filePath=FileCopyUtil.uploadFile(bucketName, type+"/"+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMM")) + "/" + fileName + substring, inputStream,SystemConfig.ossDir);
////			String filePath=FileCopyUtil.uploadFile(bucketName, type+"/"+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMM")) + "/" + UUID.randomUUID() + substring, inputStream,SystemConfig.ossDir);
////			if (!StringUtils.isEmpty(filePath)) {
////				Info entity=new Info();
////				entity.setBucketName(bucketName);
////				entity.setFilePath(filePath);
////				entity.setFileName(file.getOriginalFilename());
////				entity.setCreateTime(LocalDateTime.now());
////				entity.setFileType(type);
////				infoMapper.insert(entity);
////				return ResultUtil.data(ResultCode.RESULT_SUCCESS.getCode(), null, SystemConfig.showOssFile + filePath);
////			}
////			} catch (Exception e) {
////			e.printStackTrace();
////			return ResultUtil.data(ResultCode.RESULT_ERROR.getCode(), null, null);
////		}
////		return ResultUtil.data(ResultCode.RESULT_ERROR.getCode(), null, null);
////	}
//
//	@Override
//	public Result<String> removeFile(String url) {
//		try {
//			url=new String(Base64Utils.decode(url.getBytes()),"UTF-8");
//		} catch (UnsupportedEncodingException e) {
//			return ResultUtil.data(ResultCode.RESULT_SUCCESS.getCode(), null, null);
//		}
//		String replace = url.replace(SystemConfig.ossIp, "");
//		int indexOf = replace.indexOf("/");
//		String bucketName=replace.substring(0, indexOf);
//		String objectName=replace.substring(indexOf);
//		boolean remove = MinioUtil.remove(bucketName, objectName);
//		return ResultUtil.data(remove ? ResultCode.RESULT_SUCCESS.getCode() : ResultCode.RESULT_ERROR.getCode(), null,
//				null);
//	}
//
//	@Override
//	public Result<String> getUrl(String bucketName, String objectName) {
//		try {
//			String expiryUrl = MinioUtil.getExpiryUrl(bucketName, objectName.substring(1,objectName.length()));
//			if (StringUtils.isEmpty(expiryUrl)) {
//				return ResultUtil.data(ResultCode.RESULT_ERROR.getCode(), null, null);
//			}
//			else {
//
//				return ResultUtil.data(ResultCode.RESULT_SUCCESS.getCode(), null, expiryUrl);
//			}
//			} catch (Exception e) {
//			e.printStackTrace();
//			return ResultUtil.data(ResultCode.RESULT_ERROR.getCode(), null, null);
//		}
//	}
//
//
//	@Override
//	public InputStream downFile(String bucketName, String objectName) {
//		try {
//			 InputStream downFile = MinioUtil.downFile(bucketName, objectName);
//			 System.out.println(downFile.available());
//			return downFile;
//		} catch (Exception e) {
//			e.printStackTrace();
//			return null;
//		}
//
//	}
//
//
//}
